package cn.tedu.kcircle.category.admin.infra.repository;

import cn.tedu.kcircle.category.admin.dao.mapper.CategoryAdminMapper;
import cn.tedu.kcircle.category.admin.infra.converter.CategoryAdminConverter;
import cn.tedu.kcircle.category.admin.protocol.param.CategoryAdminAddParam;
import cn.tedu.kcircle.category.admin.protocol.param.CategoryAdminUpdateParam;
import cn.tedu.kcircle.category.admin.repository.persist.CategoryRepository;
import cn.tedu.kcircle.category.admin.service.bo.CategoryListItemBO;
import cn.tedu.kcircle.category.admin.service.bo.CategoryStandardBO;
import cn.tedu.kcircle.category.dao.entiry.CategoryDO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
@AllArgsConstructor
public class CategoryAdminRepositoryImpl implements CategoryRepository {
    private CategoryAdminMapper categoryMapper;
    private CategoryAdminConverter converter;

    @Override
    public int insert(CategoryAdminAddParam categoryAddParam) {
        log.debug("开始执行新增类别，参数：{}",categoryAddParam);
        CategoryDO categoryDO = converter.param2DO(categoryAddParam);
        return categoryMapper.insert(categoryDO);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除类别】的数据访问，参数：{}", id);
        return categoryMapper.deleteById(id);
    }

    @Override
    public int updateById(CategoryAdminUpdateParam categoryAdminUpdateParam) {
        log.debug("开始执行【更新类别】的数据访问，参数：{}", categoryAdminUpdateParam);
        CategoryDO categoryDO = converter.param2DO(categoryAdminUpdateParam);
        return categoryMapper.updateById(categoryDO);
    }


    @Override
    public Long countByName(String name) {
        log.debug("开始执行【统计匹配名称的类别的数量】的数据访问，参数：{}", name);
        return categoryMapper.selectCountByName(name);
    }



    @Override
    public CategoryStandardBO getStandardById(Long id) {
        log.debug("开始执行【根据ID查询类别信息】的数据访问，参数：{}", id);
        return categoryMapper.getStandardById(id);
    }

    @Override
    public List<CategoryListItemBO> list() {
        log.debug("开始执行【查询类别列表】的数据访问，参数：无");
        return categoryMapper.list();
    }


}
